<?php
$oCart = new Cart();
$cartlist = $oCart->get_all('*', array('userid' => $__userid), array('time' => 'DESC'));
if(empty($cartlist['list'])){
	if($__f_sysvars['url_rewrite'] == 'html' || $__f_sysvars['url_rewrite'] == 'rewrite'){
		$url = PUB_DIR.'goods/';
	}else{
		$url = WEB_DIR.'index.php?mdl=goods';
	}
	sysinfo(array('title' => '您的购物车中暂无商品，赶快选择心爱的商品吧！', 'btns' => array(
		'去选商品' => $url,
	)));
}
$vars['cartlist'] = array();
foreach($cartlist['list'] as $row){
	if(!empty($row['filename'])){
		$row['url'] = PUB_DIR.'goods/'.$row['filename'].'.html';
	}else{
		$row['url'] = PUB_DIR.'goods/'.time_to_path($row['addtime']).'/'.$row['goodsid'].'.html';
	}
	$vars['cartlist'][] = $row;
}
$vars['goods_cost'] = $cartlist['cost'];
$vars['goods_weight'] = format_weight_out($cartlist['weight'], 'kg');

// 收货地址
$oAddress = new Address();
$address_list = $oAddress->get_all('*', $_GET, array('default' => 'DESC', 'id' => 'ASC'));
if(!empty($address_list['list'])){
	$vars['address_list'] = array();
	foreach($address_list['list'] as $row){
		$row['province_name'] = $oAddress->get_province_by_id($row['province_id']);
		$row['city_name'] = $oAddress->get_city_by_id($row['city_id']);
		$row['area_name'] = $oAddress->get_area_by_id($row['area_id']);
		$vars['address_list'][] = $row;
	}
	
	$address_info = $address_list['list'][0];
	$citys = $oAddress->get_citys($address_info['province_id']);
	$areas = $oAddress->get_areas($address_info['city_id']);
	$address_info['city_options'] = make_options($citys, '', $address_info['city_id']);
	$address_info['area_options'] = make_options($areas, '', $address_info['area_id']);

	$address_info['province_name'] = $oAddress->get_province_by_id($address_info['province_id']);
	$address_info['city_name'] = $oAddress->get_city_by_id($address_info['city_id']);
	$address_info['area_name'] = $oAddress->get_area_by_id($address_info['area_id']);
}else{
	$address_info = array(
		'province_id'	=> 0,
		'besttime'		=> '',
	);
}
$provinces = $oAddress->get_provinces();
$address_info['province_options'] = make_options($provinces, '', $address_info['province_id']);
$address_info['besttime'] = make_options(Statics::$delivery_date_arr, '', $address_info['besttime']);
$vars['address_info'] = $address_info;

// 支付方式
$payments = cache_read('payments.php');
if(empty($payments)){
	$payments = array();
}
$vars['payments'] = $payments;


// 配送方式
$deliverys = cache_read('deliverys.php');
if(empty($deliverys)){
	$deliverys = array();
}else{
	foreach($deliverys as $key => $row){
		$row['deliveryDate'] = format_delivery_date_out($row['deliveryDate']);
		$deliverys[$key] = $row;
	}
}
$vars['deliverys'] = $deliverys;
?>